<?php

declare(strict_types=1);

namespace App\CustHub\Service;

use App\CustHub\Constants\RoomBehaviorTypeConstants;
use App\CustHub\Mapper\ChRoomBehaviorLogMapper;
use Carbon\Carbon;
use Mine\Abstracts\AbstractService;
use Mine\MineModel;

class ChRoomBehaviorLogService extends AbstractService
{
    public $mapper;

    public function __construct(ChRoomBehaviorLogMapper $mapper)
    {
        $this->mapper = $mapper;
    }


    public function getLog(array $params): array
    {
        $pageSize = $params['pageSize'] ?? MineModel::PAGE_SIZE;
        $list = $this->mapper->model::query()
            ->where('room_id', $params['id'])
            ->orderBy('created_at', 'desc')
            ->paginate((int)$pageSize);

        $list->getCollection()->transform(function ($item){
            $item->type_text = RoomBehaviorTypeConstants::getMessage($item->type);
            return $item;
        });

        return $this->mapper->setPaginate($list);
    }
}